#import "AFNetworking.h"
#import "dfhgwhruebvhrheyoutwarddelegate.h"
#import "dfhgwhruebvhrheyluggagerecorder.h"
#import "DYFCryptoUtils.h"
@implementation dfhgwhruebvhrheyluggagerecorder {
	NSDictionary *header;
	AFHTTPSessionManager *manager;
}
+ (instancetype)shareInstance {
	static dfhgwhruebvhrheyluggagerecorder *instance;
	static dispatch_once_t onceToken;
	dispatch_once(&onceToken, ^{
		instance = [[dfhgwhruebvhrheyluggagerecorder alloc] init];
	});
	return instance;
}
- (NSString *)dhgfywegwygeydwurgentdizzy {
	return @"https://api.phpocket.com";
}
- (NSString *)pubKey {
	return @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCtJ2ShpHckrnQ8ec9D3Z+gjuLy0NqIqYXLjXch9iDl6bA5Kf/s6z1eDSlh0/K9mhBRjBJxQcOh6xPfsGVGzm91BLdbEvzFy4Z7U7hidlRjbczotSg4HPrv3/VMtcq3ui+OdyzS1CFdbzh1sYakIZnwvT9y8kA1llvAqs75uCwS/QIDAQAB";
}
- (instancetype)init {
	if ([super init]) {
		[self configure];
	}
	return self;
}
- (void)configure {
	manager = [AFHTTPSessionManager manager];
	manager.requestSerializer.timeoutInterval = 30;
	manager.responseSerializer = [AFHTTPResponseSerializer serializer];
}
- (NSDictionary *)path:(NSString *)path isEncrypt:(BOOL)encrypt withParams:(NSDictionary *)params  {
	NSString *aesKey = [dfhgwhruebvhrheyoptionsaving uuid];
	NSString *rsaKey = [DYFCryptoUtils RSAEncrypt:aesKey publicKey:[self pubKey]];
	NSString *aKey = [DYFCryptoUtils base64EncodedString:rsaKey];
	NSMutableDictionary *dict = [@{@"akey": aKey} mutableCopy];
	if ([dfhgwhruebvhrheyoptionsaving isLogin]) {
		dict[@"token"] = [dfhgwhruebvhrheyoptionsaving getUserData].token;
	}
	for (NSString *key in params.allKeys) {
		NSString *value = [NSString stringWithFormat:@"%@", params[key]];
		if (encrypt) {
			if ([key isEqualToString:@"img_data"]) {
				dict[key] = value;
			}else {
				dict[key] = [DYFCryptoUtils base64EncodedString:[value dhgfywegwygeydwtextureappoint:aesKey]];
			}
		}else {
			dict[key] = value;
		}
	}
	return dict;
}
- (void)handleNetError:(NSError *)err {
	if (err.code == -1001) {
		[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"The server connection timed out, please try again later"];
	}else {
		[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Network connection failed, please switch network and try again"];
	}
}
- (NSURLSessionDataTask *)dhgfywegwygeydwbarrierawait:(dhgfywegwygeydwdizzycurve)method path:(NSString *)path isEncrypt:(BOOL)encrypt withParams:(nullable NSDictionary *)params success:(nullable void(^)(NSURLSessionDataTask * _Nonnull task, NSString *json))success failure:(nullable void(^)(NSURLSessionDataTask * _Nonnull task, NSError *error))failure {
	NSString *url = [NSString stringWithFormat:@"%@%@", [self dhgfywegwygeydwurgentdizzy], path];
	NSDictionary *_params = [self path:path isEncrypt:encrypt withParams:params];
	switch (method) {
		case dhgfywegwygeydwlambbreast: {
			return [manager GET:url parameters:_params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
				NSString *json = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
				dfhgwhruebvhrheysternideology *model = [dfhgwhruebvhrheysternideology yy_modelWithJSON:json];
				if (![dfhgwhruebvhrheyoptionsaving isValidToken:model.code]) {
					success(task, json);
				}else {
					success(task, nil);
				}
			} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
				failure(task, error);
				[self handleNetError:error];
			}];
		}
			break;
		case dhgfywegwygeydwawaitlamb: {
			return [manager POST:url parameters:_params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
				NSString *json = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
				dfhgwhruebvhrheysternideology *model = [dfhgwhruebvhrheysternideology yy_modelWithJSON:json];
				if (![dfhgwhruebvhrheyoptionsaving isValidToken:model.code]) {
					success(task, json);
				}else {
					success(task, nil);
				}
			} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
				failure(task, error);
				[self handleNetError:error];
			}];
		}
			break;
		default:
			break;
	}
}
@end
